package com.ls.mq.manager;

import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.log4j.Logger;

public class RedisConfig {
	private volatile static RedisConfig instance;
	private PropertiesConfiguration config;
	Logger logger = Logger.getLogger(RedisConfig.class);
	public static RedisConfig getInstance() {
		if (instance == null)
			synchronized (RedisConfig.class) {
				if (instance == null)
					instance = new RedisConfig();
			}
		return instance;
	}
	
	private RedisConfig(){
		try {
			this.config = new PropertiesConfiguration("redis.properties");
		} catch (ConfigurationException e) {
			logger.error("config redis error",e);
			throw new RuntimeException(e);
		}
	}
	
	public String get(String key){
		return this.config.getString(key);
	}
	
	public void set(String key,String value){
		this.config.setProperty(key, value);
		try {
			this.config.save();
		} catch (ConfigurationException e) {
			logger.error("set config error",e);
			throw new RuntimeException(e);
		}
	}
	
}
